package com.ebrothers.isns.view;

import java.util.Stack;

import com.ebrothers.isns.NavigationManager;
import com.ebrothers.isns.NavigationManager.NavigatedView;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ViewAnimator;

public class ViewStack extends ViewAnimator {

	private Stack<NavigatedView> mViewTracker;

	public ViewStack(Context context) {
		super(context);
		init();
	}

	public ViewStack(Context context, AttributeSet attrs) {
		super(context, attrs);
		init();
	}

	private void init() {
		mViewTracker = new Stack<NavigatedView>();
	}

	public void trackCurrentView() {
		int displayedChild = getDisplayedChild();
		NavigatedView view = NavigatedView.getNavigatedView(displayedChild);
		if (!mViewTracker.contains(view)) {
			mViewTracker.push(view);
		}
	}

	public boolean isOnTop() {
		return getDisplayedChild() == 0;
	}

	public boolean showOnTrack() {
		if (mViewTracker.isEmpty()) {
			return false;
		} else {
			NavigationManager.getInstance().navigateTo(mViewTracker.pop(),
					null, false);
			return true;
		}
	}
}
